package mpcc.mpcc.activity.trade_record;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mpcc.mpcc.activity.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public  class TradeListView {

	public TradeListView(ListView list1, Context context,List<Map<String,Object>> getlist) {
		this.list=list1;
		setmData(getlist);
		TradeAdapter adapter = new TradeAdapter(context);
		list.setAdapter(adapter);
	}

	private List<Map<String, Object>> mData;
	private ListView list;

	

	public void setmData(List<Map<String, Object>> mData) {
		this.mData = mData;
	}

	public class TradeAdapter extends BaseAdapter {
		private LayoutInflater mInflater;

		public TradeAdapter(Context context) {
			mInflater = LayoutInflater.from(context);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mData.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = mInflater.inflate(R.layout.eletrade, null);
				holder.tradeid = (TextView) convertView
						.findViewById(R.id.tradeid);
				holder.tradetype = (TextView) convertView
						.findViewById(R.id.tradetype);
				holder.tradefee = (TextView) convertView
						.findViewById(R.id.tradefee);
				holder.tradetime = (TextView) convertView
						.findViewById(R.id.tradetime);
				holder.dealparty = (TextView) convertView
						.findViewById(R.id.dealparty);
				holder.tradeid.setWidth(90);
				holder.tradetype.setWidth(90);
				holder.tradefee.setWidth(90);
				holder.tradetime.setWidth(90);
				holder.dealparty.setWidth(90);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.tradeid.setText((String) mData.get(position).get("tradeid"));
			holder.tradetype.setText((String) mData.get(position).get(
					"tradetype"));
			holder.tradefee.setText((String) mData.get(position)
					.get("tradefee"));
			holder.tradetime.setText((String) mData.get(position).get(
					"tradetime"));
			holder.dealparty.setText((String) mData.get(position).get(
					"dealparty"));
			return convertView;
		}

	}

	public final class ViewHolder {
		private TextView tradeid;
		private TextView tradetype;
		private TextView tradefee;
		private TextView tradetime;
		private TextView dealparty;

	}
}
